package com.joseph.websocket.bean;

import com.alibaba.fastjson.JSON;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

public class SessionUser {

    private String userId;

    private ChannelHandlerContext context;

    private String device;

    private String deviceId;

    private Integer deviceType;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getDevice() {
        return device;
    }

    public void setDevice(String device) {
        this.device = device;
    }

    public ChannelHandlerContext getContext() {
        return context;
    }

    public void setContext(ChannelHandlerContext context) {
        this.context = context;
    }

    public void send(Object message) {
        if (message instanceof TextWebSocketFrame) {
            context.writeAndFlush(message);
        } else {
            context.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(message)));
        }
    }
}
